package com.scvtc.config.swagger2;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Description: Swagger2 的配置类 ( 判断编写情况 )
 * @author: yiFei
 * @date: 2022/1/6 12:21
 */
@Configuration
@EnableSwagger2
@EnableKnife4j
public class Swagger2Config {

    @Value("${swagger2.enable}")
    private Boolean swagger2Enable;

    @Bean
    public Docket teacherSocialService() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("教师社会服务管理 ( 翼飞 )")
                .enable(swagger2Enable)
                .apiInfo(api())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.scvtc.controller"))
                .paths(PathSelectors.ant("/teacherSocialService/**"))
                .build();
    }

    @Bean
    public Docket researchCourseBook() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("科研教材管理 ( 翼飞 )")
                .enable(swagger2Enable)
                .apiInfo(api())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.scvtc.controller"))
                .paths(PathSelectors.ant("/researchCourseBook/**"))
                .build();
    }

    @Bean
    public Docket ResearchIntellectual() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("科研知识产权管理 ( 翼飞 )")
                .enable(swagger2Enable)
                .apiInfo(api())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.scvtc.controller"))
                .paths(PathSelectors.ant("/researchIntellectual/**"))
                .build();
    }

    @Bean
    public Docket ResearchPaper() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("科研刊物管理 ( 翼飞 )")
                .enable(swagger2Enable)
                .apiInfo(api())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.scvtc.controller"))
                .paths(PathSelectors.ant("/researchPaper/**"))
                .build();
    }

    @Bean
    public Docket ResearchWork() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("科研著作信息 ( 翼飞 )")
                .enable(swagger2Enable)
                .apiInfo(api())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.scvtc.controller"))
                .paths(PathSelectors.ant("/researchWork/**"))
                .build();
    }

    @Bean
    public Docket studentAward() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("学生获奖信息 ( 翼飞 )")
                .enable(swagger2Enable)
                .apiInfo(api())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.scvtc.controller"))
                .paths(PathSelectors.ant("/studentAwards/**"))
                .build();
    }


    @Bean
    public Docket dictionary() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("数据字典 ( 翼飞 )")
                .enable(swagger2Enable)
                .apiInfo(api())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.scvtc.controller"))
                .paths(PathSelectors.ant("/dictionary/**"))
                .build();
    }


    @Bean
    public Docket comprehensivePolicyDocment() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("政策文件 ( 翼飞 )")
                .enable(swagger2Enable)
                .apiInfo(api())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.scvtc.controller"))
                .paths(PathSelectors.ant("/comprehensivePolicyDocment/**"))
                .build();
    }

    @Bean
    public Docket teacherBase() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("教师基本信息 ( thy  翼飞 )")
                .enable(swagger2Enable)
                .apiInfo(api())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.scvtc.controller"))
                .paths(PathSelectors.ant("/teacherBase/**"))
                .build();
    }

    @Bean
    public Docket studentBase() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("学生基本信息 ( 翼飞 )")
                .enable(swagger2Enable)
                .apiInfo(api())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.scvtc.controller"))
                .paths(PathSelectors.ant("/studentsBase/**"))
                .build();
    }


    @Bean
    public Docket user() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("用户操作 ( 翼飞 )")
                .enable(swagger2Enable)
                .apiInfo(api())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.scvtc.controller"))
                .paths(PathSelectors.ant("/systemUser/**"))
                .build();
    }

    @Bean
    public Docket role() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("角色操作 ( 翼飞 )")
                .enable(swagger2Enable)
                .apiInfo(api())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.scvtc.controller"))
                .paths(PathSelectors.ant("/systemRole/**"))
                .build();
    }

    @Bean
    public Docket menu() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("菜单操作 ( 翼飞 )")
                .enable(swagger2Enable)
                .apiInfo(api())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.scvtc.controller"))
                .paths(PathSelectors.ant("/systemMenu/**"))
                .build();
    }

    @Bean
    public Docket base() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("基础操作 ( 翼飞 )")
                .enable(swagger2Enable)
                .apiInfo(api())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.scvtc.controller.common"))
                .paths(PathSelectors.any())
                .build();
    }

//    @Bean
//    public Docket docket() {
//        return new Docket(DocumentationType.SWAGGER_2)
//                .enable(swagger2Enable)
//                .apiInfo(api())
//                .select()
////  举例              .apis(RequestHandlerSelectors.basePackage("com.yifei.controller"))
//                .apis(RequestHandlerSelectors.basePackage("包名"))
////   举例           .paths(PathSelectors.ant("/studentAwards/**"))
//                .apis(RequestHandlerSelectors.basePackage("路径名字"))
//                .build();
//    }

    private ApiInfo api() {
        return new ApiInfoBuilder()
                .title("综合管理系统")
                .description("综合管理系统 Swagger 文档")
                .contact(new Contact("Scvtc", "https://www.scvtc.edu.cn/", "364398311@qq.com"))
                .version("1.0.0")
                .build();
    }

}
